package com.atguigu.gmall.oms.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Slf4j
@Component
public class RabbitMqCofig {

    @Autowired
    RabbitTemplate rabbitTemplate;


    //ORDER_EXCHANGE
    //创建延迟队列
    @Bean
    public Queue queue(){
        return QueueBuilder.durable("ORDER_TTL_QUEUE").
                withArgument("x-dead-letter-exchange", "ORDER_EXCHANGE").
                withArgument("x-dead-letter-router","order.close").
                withArgument("x-message-ttl",100000).build();
    }

    //延迟队列绑定到交换机
    @Bean
    public Binding ttlBinding(){
        return new Binding("ORDER_TTL_QUEUE",
                Binding.DestinationType.QUEUE,
                "ORDER_EXCHANGE",
                "order.ttl",null);
    }

    //创建普通队列
    @Bean
    public Queue queueClose(){
        return QueueBuilder.durable("ORDER-CLOSE-QUEUE").build();
    }

    //普通队列绑定交换机
    @Bean
    public Binding orderCloseBing(){
        return new Binding("ORDER-CLOSE-QUEUE",
                Binding.DestinationType.QUEUE,
                "ORDER_EXCHANGE",
                "order.close",null);
    }


}
